package com.ztstkj.lzservices.extension

import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan

object SpannableStringBuilderExt {
    fun SpannableStringBuilder.appendColorFontSize(text: CharSequence, colorResoureId: Int?, fontSize: Int?): SpannableStringBuilder {
        this.append(text)
        var start = this.indexOf(text.first())
        var end = this.lastIndexOf(text.last())+1
        if(colorResoureId!=null)
            this.setSpan(ForegroundColorSpan(colorResoureId), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        if(fontSize!=null)
            this.setSpan(AbsoluteSizeSpan(fontSize), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        return this
    }
}